def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def prime_d(nu):
    d = list(str(nu))
    if len(d) != 4:
        return 0
    
    prime_f = False
    m_prime = 0
    for i in range(4):
        for j in range(i+1, 4):
            num = int(''.join(d[:i] + d[i+1:j] + d[j+1:]))
            if is_prime(num):
                prime_f = True
                m_prime = max(m_prime, num)
    
    return m_prime if prime_f else 0

nu = int(input())
result = prime_d(nu)
print(result)
